//
//  JCReportStatisticsVC.m
//  SquashSpark
//
//  Created by 郭吉成 on 2017/11/30.
//  Copyright © 2017年 Coollang-YF. All rights reserved.
//

#import "JCReportStatisticsVC.h"
#import "JCClubInfoSectionHeader.h"
#import "JCReportHomeCell.h"
#import "JCReportStatisticCell.h"
#import "JCClubApi.h"
#import "JCReportModel.h"

@interface JCReportStatisticsVC ()<UITableViewDelegate, UITableViewDataSource>
@property (strong, nonatomic) JCReportModel *reportModel;

@end

@implementation JCReportStatisticsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initCode];
    [self loadData];
}

- (void)initCode{
    [_tableView registerClass:[JCClubInfoSectionHeader class] forHeaderFooterViewReuseIdentifier:NSStringFromClass([JCClubInfoSectionHeader class])];
}

- (void)loadData{
    __weak typeof(self)weakSelf = self;
    [self.hud showWithMaskType:WSProgressHUDMaskTypeClear];
    [JCClubApi getReportDetailForUserID:_userID
                                 clubID:_clubID
                                   year:_reportListModel.year
                               yearWeek:_reportListModel.yearWeek
                               complete:^(NSError *error, JCReportModel *reportModel) {
        if (error) {
            [weakSelf.hud showErrorWithString:error.domain dimissAfterSecond:2];
        }else{
            [weakSelf.hud dismiss];
            weakSelf.reportModel = reportModel;
            [weakSelf.tableView reloadData];
        }
    }];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        JCReportHomeCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([JCReportHomeCell class]) forIndexPath:indexPath];
        cell.dailyModels = _reportModel.dailyModels.mutableCopy;
        return cell;
    }else{
        JCReportStatisticCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([JCReportStatisticCell class]) forIndexPath:indexPath];
        cell.reportModel = _reportModel;
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 290;
    }else{
        return 256;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return section * kSectionHeaderHeight;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    JCClubInfoSectionHeader *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:NSStringFromClass([JCClubInfoSectionHeader class])];
    [header setleftTitle:@"Contrast Previous Week"];
    return header;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
